﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.Presenter.Support;
using Microsoft.SharePoint;
using MS.InformationManagement.Support;
using MS.InformationManagement.Support.Constants;

namespace MS.InformationManagement.Presenter.ValidarPassword
{
    public class ValidarPasswordPresenter : BasePresenter<IValidarPasswordView>
    {
        #region Constructors

        public ValidarPasswordPresenter(IValidarPasswordView view) : base(view) { }

        #endregion

        #region Public Methods

        public void VerificarUsuario()
        {
            bool haveAccesToActiveDirectory = Convert.ToBoolean(ConfigurationHelper.GetInstance().ConfigItems[GlobalConstants.VALIDAR_CREDENCIALES_FRENTE_ACTIVE_DIRECTORY]);
            if (haveAccesToActiveDirectory)
                View.result = MS.InformationManagement.BLL.ValidarPassword.ValidarPassword.ValidarUsuarioActiveDirectory(View.GuidCurrentList, View.PassWord, View.CurrentId, View.form);
            else
                View.result = MS.InformationManagement.BLL.ValidarPassword.ValidarPassword.ValidarUsuarioLocal(View.GuidCurrentList, View.PassWord, View.CurrentId, View.form);
            View.ShowResult();
        }

        public void CargarValores()
        {
            SPList currentList = SPContext.Current.Web.Lists[View.GuidCurrentList];
            SPUser currentUser = SPContext.Current.Web.EnsureUser(currentList.Title);
            View.Domain = currentUser.LoginName.Split('\\')[0];
            View.UserName = currentUser.LoginName.Split('\\')[1];
            View.Show();
        }

        #endregion
    }
}
